<?php

class Fengqiaoju_Db_Table extends Zend_Db_Table {
	
	/**
	 * 创建数据库
	 * @var unknown_type
	 */
	protected $_db;
	
	/**
	 * 表前缀
	 * @var unknown_type
	 */
	protected $_prefix;

	public function __construct() {

		$config = Zend_Registry::get ( 'config' );
		$dbConfig = $config ['database'];
		$params = array ( 
			'host' => $dbConfig ['params'] ['host'] , 'username' => $dbConfig ['params'] ['username'] , 'password' => $dbConfig ['params'] ['password'] , 'dbname' => $dbConfig ['params'] ['dbname'] 
		);
		$this->_db = Zend_Db::factory ( $dbConfig ['params'] ['adapter'], $params );
		$this->_db->query ( "SET NAMES " . $dbConfig ['params'] ['charset'] );
		Zend_Db_Table::setDefaultAdapter ( $this->_db );
		
		$this->config = Zend_Registry::get ( 'config' );
		$this->_prefix = $this->config ['database'] ['params'] ['prefix'];
		parent::__construct ();
	}

	/**
	 * 把数组组合成字符串
	 * @param array $array
	 * @param string $code = 'AND'
	 * @return string
	 */
	public function arrayToString($array , $separators = 'AND') {

		$str = '';
		foreach ( $array as $k => $v ) {
			if ($k && $v) {
				$str .= $k . "='" . $v . "' $separators ";
			}
		}
		
		if ($str) {
			return rtrim ( $str, " $separators " );
		}
		else {
			return 0;
		}
	}
}